/*
 * ContextEvent.java  0.4.0 / Oct 24, 2010
 *
 * Copyright (c) 2010 - 2011, cute4j.com and contributors.
 *
 * This software is licensed under the LGPL version 2.1 license.
 * A copy of this license is included in the file LICENSE-LGPL.txt.
 */
package com.cute4j.swing.events;

import com.cute4j.swing.Component;
import com.cute4j.swing.graphics.Point;

/**
 * Context Event (<i>right click</i> event).
 *
 * @author Slobodan Vrkacevic
 * @version 0.4.0
 */
public class ContextMenuEvent extends InputEvent {

// Public Static Fields. -------------------------------------------------------

  /**
   * Mouse caused reason id (the value is {@value}).
   */
  public static final int REASON_MOUSE = 0;

  /**
   * Mouse caused reason id (the value is {@value}).
   */
  public static final int REASON_KEYBOARD = 1;

  /**
   * Other (unknown) reason id (the value is {@value}).
   */
  public static final int REASON_OTHER = 2;

  /**
   * Other (unknown) reason id (the value is {@value}).
   */
  public static final int CONTEXT_MENU_TRIGGERED = 10001;

// Public Static Fields. -------------------------------------------------------

  private static final long serialVersionUID = 7997235136300768005L;

// Private Fields. -------------------------------------------------------------

  private final int x;
  private final int y;
  private final int globalX;
  private final int globalY;
  private final int reason;

// Public Constructors. --------------------------------------------------------

  /**
   * Constructs new MouseEvent object.
   *
   * @param source the source component
   * @param when the time the event occurred
   * @param modifiers the modifiers
   * @param reason the reason
   * @param x the x coordinate of the mouse point
   * @param y the y coordinate of the mouse point
   * @param globalX the global x coordinate of the mouse point
   * @param globalY the global y coordinate of the mouse point
   *
   * @throws IllegalArgumentException if the source is <tt>null</tt>
   */
  public ContextMenuEvent(Component source, long when, int reason,
                          int modifiers, int x, int y, int globalX,
                          int globalY) {
    super(source, CONTEXT_MENU_TRIGGERED, when, modifiers);
    this.x = x;
    this.y = y;
    this.globalX = globalX;
    this.globalY = globalY;
    this.reason = reason;
  }

// Public Methods. -------------------------------------------------------------

  /**
   * Returns the x coordinate of the mouse position relative to the source
   * component.
   *
   * @return the x coordinate
   */
  public int getX() {
    return x;
  }

  /**
   * Returns the y coordinate of the mouse position relative to the source
   * component.
   *
   * @return the y coordinate
   */
  public int getY() {
    return y;
  }

  /**
   * Returns point of the mouse pointer relative to the source component.
   *
   * @return point of the mouse pointer
   */
  public Point getPoint() {
    return new Point(x, y);
  }

  /**
   * Returns the x coordinate of the global mouse position.
   *
   * @return the x coordinate
   */
  public int getGlobalX() {
    return globalX;
  }

  /**
   * Returns the y coordinate of the global mouse position.
   *
   * @return the y coordinate
   */
  public int getGlobalY() {
    return globalY;
  }

  /**
   * Returns global mouse position.
   *
   * @return point of the mouse pointer
   */
  public Point getGlobalPoint() {
    return new Point(globalX, globalY);
  }

  /**
   * Returns reason why the event was sent.
   *
   * @return reason why the event was sent
   */
  public int getReason() {
    return reason;
  }

// Overridden Methods. ---------------------------------------------------------

  /**
   * {@inheritDoc}
   */
  public String paramString() {
    StringBuffer sb = new StringBuffer(80);
    switch (getReason()) {
      case REASON_MOUSE:
        sb.append("REASON_MOUSE");
        break;
      case REASON_KEYBOARD:
        sb.append("REASON_KEYBOARD");
        break;
      case REASON_OTHER:
        sb.append("REASON_OTHER");
        break;
      default:
        sb.append("UNKNOWN");
        break;
    }
    sb.append(",(");
    sb.append(getGlobalX());
    sb.append(',');
    sb.append(getGlobalY());
    sb.append(')');
    int modifiers = getModifiers();
    if (modifiers != 0) {
      sb.append(",modifiers=");
      sb.append(getModifiersText(modifiers));
    }
    return sb.toString();
  }

}
